<template>
  <div>
    <el-input
      ref="search"
      v-model="iconVal"
      placeholder="输入关键词搜索,注意全是英文"
      clearable
      style="width: 300px"
      @input="upIcon(iconVal)"
    />
    <div class="icons-container">
      <div class="grid">
        <div
          v-for="item of list"
          :key="item"
          @click="handleClipboard(generateElementIconCode(item), $event, item)"
        >
          <el-tooltip placement="top">
            <div slot="content">
              {{ generateElementIconCode(item) }}
            </div>
            <div class="icon-item">
              <i :class="'el-icon-' + item" />
              <span>{{ item }}</span>
            </div>
          </el-tooltip>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    iconList: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
        list:[],
        iconVal:''
    }
  },
  mounted () {
    this.list = this.iconList
  },
  methods: {
    upIcon (val) {
      if (val) {
        this.list = this.iconList.filter(item => {
          return item.toLowerCase().indexOf(val.toLowerCase()) > -1
        })
      } else {
        this.list = this.iconList
      }
    },
    generateElementIconCode (iconName) {
      return `el-icon-${iconName}`
    },
    handleClipboard (text, event, n) {
      // clip(text, event)
      this.iconChange(n)
    },
    iconChange (n) {
      this.$emit('getIcon', n)
    }
  }
}
</script>
<style lang="scss" scoped>
.icons-container {
  margin: 10px 20px 0;
  overflow: hidden;

  .grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }

  .icon-item {
    margin: 10px 20px;
    text-align: center;
    width: 100px;
    float: left;
    font-size: 30px;
    color: #24292e;
    cursor: pointer;
  }

  span {
    display: block;
    font-size: 16px;
    margin-top: 10px;
  }

  .disabled {
    pointer-events: none;
  }
}
</style>
